Skip to content

Fix validation errors for struct.wait#8394

Merged
stevenfontanella merged 2 commits intomainfrom
validation-fix
Feb 26, 2026
Merged

Fix validation errors for struct.wait#8394
stevenfontanella merged 2 commits intomainfrom
validation-fix

Conversation

@stevenfontanella
Copy link
Member

@stevenfontanella stevenfontanella commented Feb 26, 2026

Prior to #8378, any assert_invalid assertions that required a feature to be enabled spuriously succeeded even if the test would otherwise wrongly pass validation. The checks that were in wasm-validator.cpp didn't run if the ref was null or unreachable, which is wrong because the type + field index immediates could still be wrong.

Move these assertions to IRBuilder where we have the type immediate available.

Verified by removing the assert_invalid parts and checking that the error message matches what's in the test.

Part of #8315.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be best to match how we validate field indices for struct.get and struct.set, etc. I notice that's not done in IRBuilder.

@stevenfontanella
Copy link
Member Author

stevenfontanella commented Feb 26, 2026

It would be best to match how we validate field indices for struct.get and struct.set, etc. I notice that's not done in IRBuilder.

I took a look and I think the struct.set validation isn't correct today. For the null/unreachable case we drop the type immediate and infer a type that's none or unreachable, in which case some of the relevant checks are skipped (link). I checked with this module which should fail validation but passes (the arg doesn't match the struct definition and the struct field isn't mutable):

  (module
    (type $t (struct (field i32)))
    (func
      (struct.set $t 0 (ref.null $t) (f32.const 0))
    )
  )

I think IRBuilder is the right place for these validations because we still have the type immediate there, does that sound correct to you? I can also look at enabling the struct.wast spec test which is disabled now and hopefully covers this case.

@stevenfontanella stevenfontanella marked this pull request as ready for review February 26, 2026 21:59
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks. I guess we should make the same change for all other operations that take field index immediates.

@stevenfontanella stevenfontanella enabled auto-merge (squash) February 26, 2026 22:17
@stevenfontanella stevenfontanella merged commit 0887c5f into main Feb 26, 2026
17 checks passed
@stevenfontanella stevenfontanella deleted the validation-fix branch February 26, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants